<?php

namespace app\admin\model\order;

use think\Db;
use think\Model;


class OrderGoods extends Model
{

    

    

    // 表名
    protected $name = 'order_goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
    ];

    /**
     * 获取订单商品
     * $id 订单ID
     * $status 查看状态
     */
    public function getOrdergoods($id,$status='',$type="")
    {
        $where = [];
        $where['order_id'] = ['eq',$id];
        if ($status == 5 && $type== 'refund')
        {
            $where['refund_status'] = array(['eq',1],['eq',2],'or');
        }
        $ordergoods = Db::name('order_goods')->where($where)->select();
        $spec_value_str = [];
        foreach($ordergoods as $key => $val) {
            $ordergoods[$key]['order_goods'] = Db::name('goods_item')
                ->alias('i')
                ->join('goods g','g.id = i.goods_id')
                ->field('g.main_image,i.spec_value_str')
                ->where('i.id',$val['sku_id'])
                ->find();
        }

        $ordergoods = empty($ordergoods) ? [] : $ordergoods;
        return $ordergoods;
    }

}
